﻿<%@ Control Language="C#" AutoEventWireup="true" Inherits="HL.Lib.MVC.ViewControl" %>
<%
    var listItem = ViewBag.Data as List<ModNewsEntity>;
    var model = ViewBag.Model as MNewsModel;
    var Title = (!string.IsNullOrEmpty(ViewBag.Title)) ? ViewBag.Title as string : ViewPage.CurrentPage.Name;
    List<ModImageEntity> listImage = null;
    string name = string.Empty;
    string url = string.Empty;
    int count = 0;
    int width = 355, height = 265;
    var listAdv = ViewBag.Adv as List<ModAdvEntity>;
    if (listItem != null)
    {
%>
<div class="boxbig_tt conner4">
    <%=Title %>
    <%if (model.TotalRecord > model.PageSize)
      { %>
    <div class="page">
        Trang:
        <%=GetPagination(model.Page,model.PageSize,model.TotalRecord) %>
    </div>
    <%} %>
</div>
<%
WebMenuEntity obj = null;
for (int i = 0; listItem != null && i < listItem.Count; i++)
{
    listImage = ModImageService.Instance.CreateQuery()
    .Where(o => o.NewsID == listItem[i].ID)
    .ToList();
    name = listItem[i].Name;
    url = ViewPage.GetURL(listItem[i].MenuID, listItem[i].Code);
    obj = WebMenuService.Instance.GetByID(listItem[i].SizeImage);
    if (obj != null)
    {
        width = HL.Core.Global.Convert.ToInt(obj.Name.Split('*')[0], 355);
        height = HL.Core.Global.Convert.ToInt(obj.Name.Split('*')[1], 265);
    }
    if (i == 1 && listAdv != null)
    {
        for (int u = 0; u < listAdv.Count; u++)
        {
%>
<div class="adv_center">
    <a href="<%=listAdv[u].URL %>" title="<%=listAdv[u].Name %>" target="<%=listAdv[u].Target %>">
        <img src="<%=listAdv[u].File.Replace("~/","/") %>" <%if(listAdv[u].Width>0){ %>width="<%=listAdv[u].Width %>"
            <%} %> <%if(listAdv[u].Height>0){ %>height="<%=listAdv[u].Height %>" <%} %> />
    </a>
</div>
<%}
        } %>
<div class="boxbig">
    <p class="news_tt">
        <%=listItem[i].Name %></p>
    <%if (!string.IsNullOrEmpty(listItem[i].PromotionText))
      { %>
    <div class="news_saleoff">
        <img src="/Content/images/saleoff.png" /></div>
    <%} %>
    <div class="news">
        <%if (listImage != null)
          {
              count = listImage.Count - 1;  
        %>
        <div class="newspic fl">
            <a href="<%= url%>">
                <img width="<%=width %>" height="<%=height %>" src="<%=listImage[0].File.Replace("~/","/") %>"
                    alt="<%=name %>" id="<%=listItem[i].ID %>" name="0" /></a>
            <%for (int j = 0; j < listImage.Count; j++)
              {
            %>
            <img src="<%=listImage[j].File.Replace("~/","/") %>" id="img_<%=listItem[i].ID %><%=j %>"
                style="display: none" name="<%=j %>" />
            <%} %>
            <a class="newspic_next" href="javascript:;" onclick="showi('<%=listItem[i].ID %>','<%=count %>','n');return false;"
                title="next"></a><a class="newspic_back" href="javascript:;" onclick="showi('<%=listItem[i].ID %>','<%=count %>','b');return false;"
                    title="back"></a>
        </div>
        <%}
          else if (!string.IsNullOrEmpty(listItem[i].File))
          { %>
        <div class="newspic fl">
            <a href="<%= url%>">
                <img width="<%=width %>" height="<%=height %>" src="<%=listItem[i].File.Replace("~/","/") %>"
                    alt="<%=name %>" /></a>
        </div>
        <%} %>
        <div class="news_ct">
            <%if (!string.IsNullOrEmpty(listItem[i].Logo))
              { %>
            <p class="news_logo">
                <a href="<%=url %>">
                    <img src="<%=listItem[i].Logo.Replace("~/","/") %>" alt="<%=name %>" /></a></p>
            <%} %>
            <p style="text-align: center; margin: 0; padding: 0;">
                <strong><a href="<%=url %>" style="color: #787878;">
                    <%=name %></a></strong></p>
            <p style="text-align: justify">
                <%=Data.CutString(listItem[i].Summary,350) %>
            </p>
            <p class="news_bt"><a class="ct" href="<%=url %>">Chi tiết</a>
                <%if (!string.IsNullOrEmpty(listItem[i].PromotionText))
                  { %>
                  <script type="text/javascript">
                      api_gallery<%=i %>=[<%=listItem[i].PromotionText %>];
                  </script>
                <a href="javascript:;" onclick="$.prettyPhoto.open(api_gallery<%=i %>,'<%=name %>','<%=name %>');return false;"
                    rel="prettyPhoto" title="">Khuyến mãi</a>
                <%} %>
                </p>
        </div>
        <p class="clear">
        </p>
    </div>
</div>
<%} %>
<p class=" clear_10">
</p>
<div class="boxbig_tt conner4">
    <%=Title %>
    <%if (model.TotalRecord > model.PageSize)
      { %>
    <div class="page">
        Trang:
        <%=GetPagination(model.Page,model.PageSize,model.TotalRecord) %>
    </div>
    <%} %>
</div>
<script type="text/javascript">
    function showi(cid, count, state) {
        var index = document.getElementById(cid).name;
        var sid = 0;
        if (state == 'n') {
            if (index == count) sid = 0; else sid = parseInt(index) + 1;
        }
        if (state == 'b') {
            if (index == 0) sid = count; else sid = parseInt(index) - 1;
        }
        show(cid, cid + sid);
    }
    function show(cid, sid) {
        var simg = document.getElementById('img_' + sid).src;
        var sname = document.getElementById('img_' + sid).name;
        document.getElementById(cid).setAttribute('src', simg);
        document.getElementById(cid).setAttribute('name', sname);
        //$("#" + cid).attr("src", simg).attr("name", sname).fadeIn("normal");
    }
</script>
<!--slide & popup-->
<%--<script src="/Content/popup/js/jquery-1.3.2.min.js" type="text/javascript"></script>--%>
<link rel="stylesheet" href="/Content/popup/css/prettyPhoto.css" type="text/css"
    media="screen" title="Song Hỷ" charset="utf-8" />
<script src="/Content/popup/js/jquery.prettyPhoto.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
    $(document).ready(function () {
        $("area[rel^='prettyPhoto']").prettyPhoto();

        $(".gallery:first a[rel^='prettyPhoto']").prettyPhoto({ animation_speed: 'normal', theme: 'light_square', slideshow: 3000, autoplay_slideshow: true });
        $(".gallery:gt(0) a[rel^='prettyPhoto']").prettyPhoto({ animation_speed: 'fast', slideshow: 10000, hideflash: true });

        $("#custom_content a[rel^='prettyPhoto']:first").prettyPhoto({
            custom_markup: '<div id="map_canvas" style="width:260px; height:265px"></div>',
            changepicturecallback: function () { initialize(); }
        });

        $("#custom_content a[rel^='prettyPhoto']:last").prettyPhoto({
            custom_markup: '<div id="bsap_1259344" class="bsarocks bsap_d49a0984d0f377271ccbf01a33f2b6d6"></div><div id="bsap_1237859" class="bsarocks bsap_d49a0984d0f377271ccbf01a33f2b6d6" style="height:260px"></div><div id="bsap_1251710" class="bsarocks bsap_d49a0984d0f377271ccbf01a33f2b6d6"></div>',
            changepicturecallback: function () { _bsap.exec(); }
        });
    });
			</script>
<style type="text/css" media="screen">
    .bsap a
    {
        float: left;
    }
</style>
<script type="text/javascript">
    (function () {
        var bsa = document.createElement('script');
        bsa.type = 'text/javascript';
        bsa.async = true;
        bsa.src = '//s3.buysellads.com/ac/bsa.js';
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(bsa);
    })();
			</script>
<!--end popup-->
<%} %>
